package day7;

import java.util.Random;

public class User {
    int id;
    String username;
    String password;
    static double money;
    public void setPassword(String password){
        //this.属性
        this.password=password;
    }
    public void add(User user){
        setPassword(user.password);
        //this可用可不用
        this.setPassword(user.password);
    }
    public User() {
        //this();
        System.out.println("无参构造");
        Random r= new Random();
        this.id=r.nextInt(9000)+1000;//随机
    }
    public User(String username, String password) {
        this();
        System.out.println("两个");
        this.username = username;
        this.password = password;
    }
    public User(int id,String username, String password, double money){
        //只能用在构造方法中 并且只能放在第一行
        //避免出现循环引用的问题
        //this();
        this(username,password);
        System.out.println("4个");
        this.money=money;
    }
    public void print(){
        System.out.println("编号"+id);
        System.out.println("账号"+username);
        System.out.println("密码"+password);
        System.out.println("余额"+money);
    }
    public static void main(String[] args) {
     User u=new User(0,"123","admin",1000);
     u.print();
     //this.print();   静态方法不能使用this
     User u2 = new User();
     u2.print();
        System.out.println(u2.money);//不推荐
        System.out.println(User.money);
    }
}
